/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.customer.facade.order.register;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import info.peigen.hotpot.business.customer.facade.enums.CustomerSource;
import info.peigen.hotpot.business.customer.facade.order.base.CustomerServiceOrderBase;
import info.peigen.hotpot.common.core.result.ResultCode;
import info.peigen.hotpot.common.service.base.exception.BusinessException;
import jakarta.validation.constraints.NotEmpty;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;

/**
 * <b>(CustomerRegisterOrder)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/7/28
 */
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
public class CustomerRegisterOrder extends CustomerServiceOrderBase {
    /** 登录名-可用手机号或邮箱 */
    @NotEmpty
    String loginName;
    /** 登录密码 */
    @NotEmpty
    String loginPassword;
    /** 再次输入登录密码 */
    @NotEmpty
    String confirmPassword;
    /** 验证码 */
    String verificationCode;
    /** 客户来源 */
    @Builder.Default
    CustomerSource source = CustomerSource.Self;

    @Override
    public void check() {
        super.check();
        Assert.isTrue(StrUtil.equals(loginPassword, confirmPassword), () -> new BusinessException(ResultCode.FAILURE, "两次密码不一致!"));
    }
}